OPTIONS NOFMTERR MPRINT PS=60 LS=80 sasautos =macro;
FILENAME macro "/disk/agedisk2/medicare.work/newhouse-DUA19577/jeff/programs/macro";


libname r '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru';
libname wk2 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2007';
libname wk '/disk/agebulk2/medicare.work/newhouse-DUA19577';
libname perm '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru/diab';
libname tab '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru/price_tables';
libname pm2  '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/patient_cohorts';
libname perm7 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru/diab/2007';
libname hed '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/MA_files';
libname pb '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru/diab/partb/2007';
libname ip '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru/diab/ip/2007';
libname op '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/rru/diab/op/2007';


***RRU DIABETES RESULTS;
data rru (drop = esrd);
set perm7.diab2007 (keep = ed_vis ip_vis ip_cost em_cost surg_cost
 comorb type bene_id aids organ esrd cancer hmocov enrld);
if aids ~= 1 and  organ ~= 1 and esrd ~= 1 and cancer ~= 1;
if enrld in (1,2) and hmocov = "00";
proc sort;
 by bene_id;

data den;
 length racec $ 10;
 set wk2.results07 (keep= bene_id enrld sex county
 esrd hmocov nurs age race state zip5 months);
 where age >= 65 and age <= 75 and enrld in (1,2) and esrd ~= "Y";
 if hmocov = 0 and esrd ~= "Y" and nurs ~in ("both", "long");
 if state > "53" or state in ("40", "48") then delete;
racec = race;
if racec = "0" then racec = "0.Unknown";
if racec = "1" then racec = "1.White";
if racec = "2" then racec = "2.Black";
if racec = "3" then racec = "3.Other";
if racec = "4" then racec = "4.Asian";
if racec = "5" then racec = "5.Hispanic";
if racec = "6" then racec = "6.Native";
if racec in ("0.Unknown", "4.Asian", "6.Native") then racec = "3.Other";


 if state in ("20", "30", "47", "22", "41", "07") then region=1; 
 else if state in ("33", "31", "39") then region=1; 
 else if state in ("23", "36", "14", "15", "52") then region=2; 
 else if state in ("24", "26", "16", "35", "43", "28", "17") then region=2; 
 else if state in ("08", "21", "09", "51", "49", "34", "42", "11", "10") then region=3; 
 else if state in ("18", "44", "01", "25") then region=3; 
 else if state in ("04", "19", "37", "45") then region=3; 
 else if state in ("27", "13", "53", "29", "46", "06", "03", "32") then region=4; 
 else if state in ("50", "38", "05", "12", "02") then region=4; 


ffs_count = months/12;

length gender $ 8;
gender = sex;

if gender = "1" then gender = "1.Male";
if gender = "2" then gender = "2.Female";

if age >= 65 and age <= 70 then newagec = "1. 65-70";
else if age > 70 and age <= 75 then newagec = "2. 71-75";

if zip5 = "00000" then zip5 = "00001";
if zip5 = "99999" then zip5 = "99998";
proc sort;
 by bene_id;

data rru;
 merge rru (in=rr) den (in=d);
 by bene_id;
 if rr*d;


proc freq;
 tables gender racec age region comorb type;

proc print data=rru (obs=100);



